from django.db import models

# Create your models here.


class Item(models.Model):
    PRINT_STATUS = (
        (0, '未打印'),
        (1, '已打印'),
    )

    ABANDON_STATUS = (
        (0, '否'),
        (1, '是'),
    )

    receipt = models.CharField('单号', null=True, blank=True,max_length=30)     # 2020326 + 4位数
    register_name = models.CharField('公司名', max_length=200, null=True, blank=True)
    license_num = models.CharField('车牌号', max_length=20, null=True, blank=True)
    payment_account = models.FloatField('登记费', null=True, blank=True)
    is_print = models.SmallIntegerField('是否打印', default=0, choices=PRINT_STATUS)
    is_abandon = models.SmallIntegerField('是否作废', default=0, choices=ABANDON_STATUS)
    remark = models.TextField('备注', null=True, blank=True, default='')

    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    # update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)

    def __str__(self):
        return self.receipt

    def to_dict(self):
        return {
            'id': self.id,
            'receipt': self.receipt,
            'register_name': self.register_name,
            'license_num': self.license_num,
            'payment_account': self.payment_account,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S'),
            'remark': self.remark,
            # 'is_print': self.is_print,
            # 'is_abandon': self.is_abandon,
        }

    class Meta:
        verbose_name = '条目信息'
        verbose_name_plural = verbose_name
        ordering = ['-create_time']

